﻿using Newtonsoft.Json.Linq;
using SqlKata.Compilers;
using SqlKata.Execution;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace U8WebService.Common
{
    public partial class Katabase
    {
        QueryFactory SqlServerDb(string dataSource, string userId, string password, string database)
        {
            var connection = new SqlConnection($@"Server={dataSource};User Id={userId};Password={password};Database={database};");
            var compiler = new SqlServerCompiler();

            return new QueryFactory(connection, compiler);
        }
        QueryFactory SqlServerDb(string connectionString)
        {
            var connection = new SqlConnection(connectionString);
            var compiler = new SqlServerCompiler();

            return new QueryFactory(connection, compiler);
        }
    }
    public partial class Katabase
    {
        public QueryFactory U8Db()
        {
            return SqlServerDb(
                ConfigReader.Reader["Server"],
                 ConfigReader.Reader["DbAccount"],
                ConfigReader.Reader["DbPWD"],
                ConfigReader.Reader["DbName"]);
        }

        
    }

}